﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ShoppingList
{
    public partial class Import : Form
    {
        public List<ShoppingItem> SelectedItems
        {
            get {
                List<ShoppingItem> importItems = new List<ShoppingItem>();
                foreach (ListViewItem lviItem in lstItems.Items)
                {
                    if (lviItem.Checked)
                    {
                        //create a new shopping item with a new unique id
                        ShoppingItem newItem = new ShoppingItem(lviItem.Text);
                        importItems.Add(newItem);
                    }
                }
                return importItems;
            }
        }

        public Import()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Show the dialog with the items supplied. 
        /// </summary>
        /// <param name="items"></param>
        public DialogResult ShowDialog(string[] importItems, ShoppingList currentList)
        {
            lstItems.Items.Clear();
            for(int i=1; i<importItems.Length;i++)
            {
                if (!currentList.ContainsItemName(importItems[i]))
                {
                    ListViewItem newItem = new ListViewItem(importItems[i]);
                    newItem.Checked = true;
                    lstItems.Items.Add(newItem);
                }
            }
            return ShowDialog();
        }

        private void miCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}